#include <iostream>
using namespace std;

const int N = 1e5 + 10;
int n, q;
int a[N];

int binary_search(int x, int y)
{
    // 查找大于等于 x 的最小值
    int l = 1, r = n;
    while(l < r)
    {
        int m = (l + r) / 2;
        if(a[m] >= x) r = m;
        else l = m + 1;
    }
    if(a[l] < x) return 0;
    int tmp = l;
    // 小于等于y的最大值
    l = 1, r = n;
    while(l < r)
    {
        int m = (l + r + 1) / 2;
        if(a[m] <= y) l = m;
        else r = m - 1;
    }
    if(a[l] > y) return 0;
    return l - tmp + 1;
}
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= q; i++)
    {
        int x, y; cin >> x >> y;
        cout << binary_search(x, y) << endl;
    }
    return 0;
}